package com.example.android09_preference;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	private TextView interCall;
	private TextView rTone;
	private TextView sleepMode;
	private ImageButton settings;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		interCall = (TextView) findViewById(R.id.interCall);
		rTone = (TextView) findViewById(R.id.rtone);
		sleepMode = (TextView) findViewById(R.id.sleepMode);
		settings = (ImageButton) findViewById(R.id.setting);
		settings.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, EditActivity.class);
				startActivity(intent);				
			}
		});
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		SharedPreferences sharedPreperence = PreferenceManager.getDefaultSharedPreferences(this);
		interCall.setText(sharedPreperence.getString("ringtone", "anonymous"));
		sleepMode.setText(new Boolean(sharedPreperence.getBoolean("sleepMode", false)).toString());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
